﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// GridViewLinkButtonTemplate 的摘要说明
/// </summary>
public class GridViewLinkButtonTemplate : ITemplate
{
    // 数据列名
    private string fieldName;
    // 控件ID
    private string controlId;
    //商品ID
    private string productId;
    //评价等级ID
    private string levelId;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="controlId"></param>
    /// <param name="fieldName"></param>
    public GridViewLinkButtonTemplate(string controlId, string fieldName,string productId,string levelId)
    {
        this.controlId = controlId;
        this.fieldName = fieldName;
        this.productId = productId;
        this.levelId = levelId;
    }

    /**/
    /// <summary>
    /// 实现ITemplate的InstantiateIn方法
    /// </summary>
    /// <param name="container">控件容器</param>
    public void InstantiateIn(System.Web.UI.Control container)
    {
        HyperLink hlink = new HyperLink();
        hlink.ID = controlId;
        hlink.DataBinding += new EventHandler(HyperLinkTemplate_DataBinding);
        container.Controls.Add(hlink);

    }
    /**/
    /// <summary>
    /// 绑定事件处理
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void HyperLinkTemplate_DataBinding(object sender, System.EventArgs e)
    {
        HyperLink hlink;
        hlink = (HyperLink)sender;
        GridViewRow container = (GridViewRow)hlink.NamingContainer;
        hlink.Text += DataBinder.Eval(container.DataItem, fieldName);
        hlink.NavigateUrl += "~/DayToDayManagement/ProductCommentDetail.aspx?productId=" + DataBinder.Eval(container.DataItem,productId) + "&level=" +levelId;

    }
}
